package com.houger.ddd.seckill.infra.datamanager;


import com.houger.ddd.datamanager.manager.aop.DataCache;
import com.houger.ddd.datamanager.manager.aop.DataCacheEvict;
import com.houger.ddd.datamanager.utils.CacheType;
import com.houger.ddd.seckill.infra.entity.ActivityTemplateBizConfig;
import com.houger.ddd.seckill.repository.ActivityTemplateBizConfigRepository;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class ActivityTemplateBizConfigDataManager {

    @Resource
    ActivityTemplateBizConfigRepository activityTemplateBizConfigRepository;

    @DataCache(group = "activity-biz",key = "('templateId=').concat(#templateId)",type = {CacheType.LOCAL, CacheType.REDIS},localExpire = 1 * 60, redisExpire = 1 * 60)
    public ActivityTemplateBizConfig queryBizByTemplateId(Long templateId) {
        return this.activityTemplateBizConfigRepository.findByTemplateId(templateId).orElseThrow();
    }

    @DataCache(group = "activity-biz",key = "('templateCode=').concat(#templateCode)",type = {CacheType.LOCAL, CacheType.REDIS},localExpire = 1 * 60, redisExpire = 1 * 60)
    public ActivityTemplateBizConfig queryBizByTemplateCode(String templateCode) {
        return this.activityTemplateBizConfigRepository.findByTemplateCode(templateCode);
    }

    @DataCacheEvict(group = "activity-biz",key = {
            "('templateId=').concat(#templateId)",
            "('templateCode=').concat(#templateCode)"},
            type = {CacheType.LOCAL, CacheType.REDIS})
    public void evict(Long templateId, String templateCode){

    }

}
